/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.search;

import br.com.deployment.daoImpl.ExecutorDAOImpl;
import br.com.deployment.daoImpl.OrganDAOImpl;
import br.com.deployment.entities.Address;
import br.com.deployment.entities.Executor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerSearchExecutor {
    
    @EJB
    ExecutorDAOImpl executorService;
    @EJB
    OrganDAOImpl organService;
    
    // Lista de Executores do View Executor
    private List<Executor>  executors;
    
    // Lista de Executores da Pesquisa 
    private List<Executor>  searchExecutors;
    
    // Objeto para Pesquisa
    private Executor executor;
    
    // Objeto para vizualizar
    private Executor  showExecutor;
    
    private Address   address;
  
    
    public ManagerSearchExecutor(){
        executors = new ArrayList<Executor>();
        executor  = new Executor();
    }
    
    // Pesquisar Executor
    public void searchExecutor(){
        searchExecutors = executorService.findExecutor(executor);
    }
    
    // Mostra o Objeto Executor Selecionado e Redireciona para a página
    public void redirect(String string, Executor e) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            this.showExecutor = e;
            this.address = this.showExecutor.getAddress();
            this.showExecutor.setOrgan(organService.find(showExecutor.getOrgan().getId()));
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerEditExecutor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
    public List<Executor> lstEscutors(){
        return executors = executorService.findAll();
    }

    public List<Executor> getExecutors() {
        return executors;
    }

    public void setExecutors(List<Executor> executors) {
        this.executors = executors;
    }

    public Executor getExecutor() {
        return executor;
    }

    public void setExecutor(Executor executor) {
        this.executor = executor;
    }

    public Executor getShowExecutor() {
        return showExecutor;
    }

    public void setShowExecutor(Executor showExecutor) {
        this.showExecutor = showExecutor;
    }

    public List<Executor> getSearchExecutors() {
        return searchExecutors;
    }

    public void setSearchExecutors(List<Executor> searchExecutors) {
        this.searchExecutors = searchExecutors;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    
    
    
    
}
